﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using DHQGHN.PM0.Common.Attributes;

namespace DHQGHN.PM0.Models.Admin
{
    public class OccupationModel
    {
        public string OCCUPATION_ID { get; set; }
        [Required(AllowEmptyStrings = false, ErrorMessageResourceName = "Error_HaventPutOcNameYet",ErrorMessageResourceType=typeof(Resources.Localization))]
        [Remote("CheckExistOcName", "Occupation", ErrorMessageResourceName = "OcNameExist",ErrorMessageResourceType=typeof(Resources.Localization), HttpMethod = "POST", AdditionalFields = "OCCUPATION_ID")]
        [StringLength(250, ErrorMessageResourceName = "Error_OcNameLength",ErrorMessageResourceType=typeof(Resources.Localization))]
        [LocalizationDisplay("OcName")]
        public string NAME { get; set; }
        [Required(AllowEmptyStrings = false, ErrorMessageResourceName = "Error_HaventPutOcCodeYet",ErrorMessageResourceType=typeof(Resources.Localization))]
        [Remote("CheckExistOcCode", "Occupation", ErrorMessageResourceName = "OcCodeExist",ErrorMessageResourceType=typeof(Resources.Localization), HttpMethod = "POST", AdditionalFields = "OCCUPATION_ID")]
        [StringLength(5, ErrorMessageResourceName = "Error_OcCodeLength",ErrorMessageResourceType=typeof(Resources.Localization))]
        [LocalizationDisplay("OcCode")]
        public string CODE { get; set; }
        public string LEVEL { get; set; }
        [LocalizationDisplay("OcParent")]
        public string PARENT { get; set; }
        [LocalizationDisplay("OcParentName")]
        public string PARENT_NAME { get; set; }
        public string CODE4 { get; set; }
        [LocalizationDisplay("OcDescriptions")]
        [StringLength(250, ErrorMessageResourceName = "Error_OcDescriptionLength",ErrorMessageResourceType=typeof(Resources.Localization))]
        public string DESCRIPTIONS { get; set; }
        public int DELETED { get; set; }
        public SelectList lstParent;
        public int RecordCount { get; set; }
        public OccupationModel()
        {

        }

        public OccupationModel(DAL.Models.Admin.OccupationModel ocModel)
        {
            // TODO: Complete member initialization
            OCCUPATION_ID = ocModel.OCCUPATION_ID;
            CODE = ocModel.CODE;
            LEVEL = ocModel.LEVEL;
            PARENT = ocModel.PARENT;
            PARENT_NAME = ocModel.PARENT_NAME;            
            NAME = ocModel.NAME;
            DESCRIPTIONS = ocModel.DESCRIPTIONS;
            DELETED = ocModel.DELETED;
            RecordCount = ocModel.RecordCount;
        }

        internal DAL.Models.Admin.OccupationModel toDALModel()
        {
            DAL.Models.Admin.OccupationModel ocModel = new DAL.Models.Admin.OccupationModel
            {
                OCCUPATION_ID = OCCUPATION_ID,
                CODE = this.CODE != null ? this.CODE.Trim() : null,
                LEVEL = LEVEL,
                PARENT = this.PARENT !=null && !"-1".Equals(this.PARENT)?this.PARENT:null,
                CODE4 = CODE4,
                NAME = this.NAME != null ? this.NAME.Trim() : null,
                DESCRIPTIONS = DESCRIPTIONS,
                DELETED = DELETED,
                RecordCount = RecordCount
            };
            return ocModel;
        }
    }
}
